]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ibusManager: Simplify code a bit
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 23 Mar 2020 22:22:17 +0000 (23:22 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 24 Mar 2020 07:27:27 +0000 (08:27 +0100)
ibus_bus_request_name_async_finish() will throw an error on failure,
so we can move the error handling there instead of checking for the
return value, which saves one level of indentation.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1122

js/misc/ibusManager.js

index e27e9f06dd1697e1df33a2284525671fe5aeb069..a55701ed01230a79a231bd500d02eaaa30e77641 100644 (file)
@@ -127,56 +127,55 @@ var IBusManager = class {
     }
 
     _initPanelService(ibus, result) {
-        let success = false;
         try {
-            success = !!this._ibus.request_name_async_finish(result);
+            this._ibus.request_name_async_finish(result);
         } catch (e) {
-            if (e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
-                return;
-            logError(e);
+            if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
+                logError(e);
+                this._clear();
+            }
+            return;
         }
 
-        if (success) {
-            this._panelService = new IBus.PanelService({ connection: this._ibus.get_connection(),
-                                                         object_path: IBus.PATH_PANEL });
-            this._candidatePopup.setPanelService(this._panelService);
-            this._panelService.connect('update-property', this._updateProperty.bind(this));
-            this._panelService.connect('set-cursor-location', (ps, x, y, w, h) => {
-                let cursorLocation = { x, y, width: w, height: h };
-                this.emit('set-cursor-location', cursorLocation);
-            });
-            this._panelService.connect('focus-in', (panel, path) => {
-                if (!GLib.str_has_suffix(path, '/InputContext_1'))
-                    this.emit('focus-in');
-            });
-            this._panelService.connect('focus-out', () => this.emit('focus-out'));
+        this._panelService = new IBus.PanelService({
+            connection: this._ibus.get_connection(),
+            object_path: IBus.PATH_PANEL,
+        });
+        this._candidatePopup.setPanelService(this._panelService);
+        this._panelService.connect('update-property', this._updateProperty.bind(this));
+        this._panelService.connect('set-cursor-location', (ps, x, y, w, h) => {
+            let cursorLocation = { x, y, width: w, height: h };
+            this.emit('set-cursor-location', cursorLocation);
+        });
+        this._panelService.connect('focus-in', (panel, path) => {
+            if (!GLib.str_has_suffix(path, '/InputContext_1'))
+                this.emit('focus-in');
+        });
+        this._panelService.connect('focus-out', () => this.emit('focus-out'));
 
+        try {
+            // IBus versions older than 1.5.10 have a bug which
+            // causes spurious set-content-type emissions when
+            // switching input focus that temporarily lose purpose
+            // and hints defeating its intended semantics and
+            // confusing users. We thus don't use it in that case.
+            _checkIBusVersion(1, 5, 10);
+            this._panelService.connect('set-content-type', this._setContentType.bind(this));
+        } catch (e) {
+        }
+        // If an engine is already active we need to get its properties
+        this._ibus.get_global_engine_async(-1, this._cancellable, (_bus, res) => {
+            let engine;
             try {
-                // IBus versions older than 1.5.10 have a bug which
-                // causes spurious set-content-type emissions when
-                // switching input focus that temporarily lose purpose
-                // and hints defeating its intended semantics and
-                // confusing users. We thus don't use it in that case.
-                _checkIBusVersion(1, 5, 10);
-                this._panelService.connect('set-content-type', this._setContentType.bind(this));
+                engine = this._ibus.get_global_engine_async_finish(res);
+                if (!engine)
+                    return;
             } catch (e) {
+                return;
             }
-            // If an engine is already active we need to get its properties
-            this._ibus.get_global_engine_async(-1, this._cancellable, (_bus, res) => {
-                let engine;
-                try {
-                    engine = this._ibus.get_global_engine_async_finish(res);
-                    if (!engine)
-                        return;
-                } catch (e) {
-                    return;
-                }
-                this._engineChanged(this._ibus, engine.get_name());
-            });
-            this._updateReadiness();
-        } else {
-            this._clear();
-        }
+            this._engineChanged(this._ibus, engine.get_name());
+        });
+        this._updateReadiness();
     }
 
     _updateReadiness() {